<?php
ob_start();
session_start(); //Initialize php-session
/*****************************************************************
 * Fusion.Board
 *
 * @author                Denis Wrobel
 * @license               http://www.gnu.org/licenses/gpl-3.0.html
 * @version               0.1
 *
 *****************************************************************/

//error_reporting( 0 ); //Turn off error reporting by php parser


########################## PHP ENVIRONMENT ##########################
define( 'IN_SCRIPT', true ); //Define that we are in script
define( 'ROOT'     , './' ); //Root directory

require_once( ROOT . 'constants.php' );
require_once( KERNEL . 'Config.php' );


if( strpos( 'ApacheBench', $_SERVER['USER_AGENT'] ) !== false && BLOCK_AB )
{
    die('ApacheBench is blocked');
}
#####################################################################


########################## CLASSES ##########################
require_once( CLASSES . 'template.Class.php' );
require_once( CLASSES . 'mysql.Class.php' );
require_once( CLASSES . 'error.Class.php' );
require_once( CLASSES . 'cache.Class.php' );
require_once( CLASSES . 'user.Class.php' );
require_once( CLASSES . 'language.Class.php' );
require_once( CLASSES . 'page.Class.php' );
require_once( CLASSES . 'plugin.Class.php' );
require_once( CLASSES . 'core.Class.php' );
require_once( CLASSES . 'forum.Class.php' );
require_once( CLASSES . 'recaptcha.Class.php' );
require_once( CLASSES . 'mail.Class.php' );

$core  = new Core;

$cache = new Cache;

$db       = new DataBase( $dbconfig );

$template = new Template;
$template->template = $board['template'];
$template->root = TEMPLATES;
$template->compile = COMPILED;
$template->checkData();

$user     = new User;
$session  = $user->initialize();

$language = new Language;

$page     = new Page;

$plugin   = new PluginManager;

$recaptcha = new ReCaptcha;

$mail     = new Mail;

if( $core->_GET( 'mode' ) == 'profile' )
{
    //Localization update
    if( $core->_POST( 'localization' ) )
    {
        if( $session['session_logged'] )
        {
            $localization = $core->filterItem( $core->_POST( 'localization' ) );
            
            if( strlen( $localization ) > 30 )
            {
                echo 0 . '|' . $language->string( 'localization_too_long' );
            }
            else
            {
                $db->query( 'UPDATE ' . TABLE_PREFIX . 'users
                             SET user_localization = \'' . $db->escape( $localization ) .'\'
                             WHERE user_id = \'' . $session['user_id'] . '\'' );
                
                echo $core->htmlFilter( $localization );
            }
        }
        
        die;
    }
    
    //Hobby update
    if( $core->_POST( 'hobby' ) )
    {
        if( $session['session_logged'] )
        {
            $hobby = $core->filterItem( $core->_POST( 'hobby' ) );
            
            if( strlen( $hobby ) > 30 )
            {
                echo 0 . '|' . $language->string( 'hobby_too_long' );
            }
            else
            {
                $db->query( 'UPDATE ' . TABLE_PREFIX . 'users
                             SET user_hobby = \'' . $db->escape( $hobby ) .'\'
                             WHERE user_id = \'' . $session['user_id'] . '\'' );
                
                echo $core->htmlFilter( $hobby );
            }
        }
        
        die;
    }
    
    //profession update
    if( $core->_POST( 'profession' ) )
    {
        if( $session['session_logged'] )
        {
            $profession = $core->filterItem( $core->_POST( 'profession' ) );
            
            if( strlen( $profession ) > 30 )
            {
                echo 0 . '|' . $language->string( 'profession_too_long' );
            }
            else
            {
                $db->query( 'UPDATE ' . TABLE_PREFIX . 'users
                             SET user_profession = \'' . $db->escape( $profession ) .'\'
                             WHERE user_id = \'' . $session['user_id'] . '\'' );
                
                echo $core->htmlFilter( $profession );
            }
        }
        
        die;
    }
}
?>